def isPrime(x):
    for y in range(2 , int(x**0.5)+1):
        if x%y==0:
            return 0
    return 1
s=input().split()
t=['zero','one','two','three','four','five','six','seven','eight','nine']
rez=0
d=100
for x in s:
    for i in range(len(t)):
        if x==t[i]:
            rez +=i*d
            d=d//10
            break

if len(s)==3:
    flag=True
else:
    flag=False
delta=1
while flag:
    if  isPrime (rez-delta):
        print(rez-delta)
        break
    if isPrime(rez+delta):
        print(rez+delta)
        break
    delta+=1
if flag== False:print('wrong input')
